package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCDemo9 {
    public static void main(String[] args) throws SQLException {
        try (Connection connection=DBUtil.getConnection();){
            String sql ="INSERT INTO user(username,password,nickname,age) "+
                    "VALUES(?,?,?,?)";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1,"admin");
            preparedStatement.setString(2,"123123");
            preparedStatement.setString(3,"管理员");
            preparedStatement.setInt(4,18);
            int num =preparedStatement.executeUpdate();
            System.out.println(num>0?"添加成功":"添加失败");
            connection.commit();


        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
